package com.lc.pianostudent.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;

import com.lc.pianostudent.BaseApplication;
import com.lc.pianostudent.R;
import com.lc.pianostudent.conn.PostrResetPasswordNext;
import com.lc.pianostudent.util.Validator;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;
import com.zcx.helper.view.AppPassword;


/**
 * Created by Administrator on 2018/6/22.
 */

public class ForgetNextActivity extends BaseActivity implements View.OnClickListener{
    @BoundView(R.id.forget_pass_next) private AppPassword forget_pass_next;
    @BoundView(R.id.set_new_password) private AppPassword set_new_password;
    @BoundView(value = R.id.set_pass_button,isClick = true) private LinearLayout set_pass_button;
    //重置密码接口
    private PostrResetPasswordNext postrResetPasswordNext = new PostrResetPasswordNext(new AsyCallBack<PostrResetPasswordNext.PostrResetPasswordNextInfo>(){

        @Override
        public void onSuccess(String toast, int type, Object o, PostrResetPasswordNext.PostrResetPasswordNextInfo postrResetPasswordNextInfo) throws Exception {
            if (postrResetPasswordNextInfo.code.equals("200")) {
                UtilToast.show(toast);

                BaseApplication.INSTANCE.finishActivity(ForgetPassActivity.class,ForgetNextActivity.class);

            } else {
                UtilToast.show(toast);
            }

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(toast);

        }
    });
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget_next);

        setBackTrue();
        initView();
    }

    private void initView(){
        setTitleName("密码设置");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.set_pass_button:
                String newPwd = forget_pass_next.getText().toString().trim();
                String conPwd = set_new_password.getText().toString().trim();

                if (TextUtils.isEmpty(newPwd)) {
                    UtilToast.show("请输入新密码");
                } else if (TextUtils.isEmpty(conPwd)) {
                    UtilToast.show("请输入确认密码");
                } else if (!Validator.isPassword2(newPwd)) {
                    UtilToast.show("请输入6-12位数字、英文");
                }else if (!Validator.isPassword2(conPwd)) {
                    UtilToast.show("请输入6-12位数字、英文");
                }else if (!conPwd.equals(newPwd)) {
                    UtilToast.show("两次输入的密码不一致");
                } else {
                    postrResetPasswordNext.username = getIntent().getStringExtra("phone");
                    postrResetPasswordNext.password = newPwd;
                    postrResetPasswordNext.confirm_password = conPwd;
                    postrResetPasswordNext.execute();
                }
                break;

            default:
                break;
        }
    }
}
